package com.work.music.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Component;

@Component
public class EmailSend {

    @Autowired
    private JavaMailSenderImpl javaMailSender;

    /**
     * 发送普通邮件
     * @param email
     * @param yzcode
     * @param type
     */
    public void sendEmailCode(String email, String yzcode, int type) {
        String title = "";
        if(type == 0) {
            title = "注册";
        } else if(type == 1) {
            title = "忘记密码";
        } else if(type == 2) {
            title = "三方绑定邮箱";
        } else {
            return;
        }
        sendEmail(title, "您的"+title+"验证码是：" + yzcode + "。请在5分钟之内完成，若非本人操作，请忽略。", email);
    }

    /**
     * 发送邮件
     * @param title 主题
     * @param content 内容
     * @param email 邮箱地址
     */
    public void sendEmail(String title, String content, String email) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setSubject(title);
        simpleMailMessage.setText(content);
        simpleMailMessage.setTo(email);
        simpleMailMessage.setFrom("xufangsheng10835@163.com");
        javaMailSender.send(simpleMailMessage);
    }
}
